package com.hwl.lab.service;

import com.hwl.lab.entity.Canhe;
import com.hwl.lab.repository.CanheRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CanheService {
    @Autowired
    private CanheRepository canheRepository;
    //分页实现
    public Page<Canhe> findAll(Integer page, Integer size){
        Pageable pageable=  PageRequest.of(page-1,size);
        return canheRepository.findAll(pageable);
    }
    //不分页
    public List<Canhe> findAll() {
        return canheRepository.findAll();
    }
    //通过账号查询
    public Canhe findByCanheid(String canheid){
        return canheRepository.findByCanheid(canheid);
    }
    //保存，修改
    public Canhe saveCanhe(Canhe canhe){
       return  canheRepository.save(canhe);
    }
    //通过账号删除
    public void deleteById(Long id){
        canheRepository.deleteById(id);
    }
}
